package com.example.demo.controller;

import org.springframework.boot.Banner;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @RequestMapping("/user/login")
    //先看能不能进来，为什么要加@ResponseBody
   // @ResponseBody
    //保险起见
    public String login(@RequestParam("username") String username, @RequestParam("password") String password, Model model,HttpSession session){
        if(!StringUtils.isEmpty(username)&&"1128".equals(password)){
            session.setAttribute("loginUser",username);
            return "redirect:main.html";
            //return "dashboard";
        }else{
            //使用model传值
            model.addAttribute("msg", "密码是千玺生日");
            return "index";
        }
  }
}
